#include <cstring>
#include <iostream>

using namespace std;

const int N = 210;

int n, m;
bool g[N][N], st[N];
int match[N];

bool find(int x) {
    for (int i = 1; i <= n; ++ i) {
        if (!st[i] && g[x][i]) {
            st[i] = true;
            int t = match[i];
            if (!t || find(t)) {
                match[i] = x;
                return true;
            }
        }
    }
    
    return false;
}

int main() {
    cin >> n >> m;
    
    while (m -- ) {
        int x, y;
        cin >> x >> y;
        g[x][y] = true;
    }
    
    for (int k = 1; k <= n; ++ k)
        for (int i = 1; i <= n; ++ i)
            for (int j = 1; j <= n; ++ j)
                g[i][j] |= g[i][k] &g[k][j];
    
    
    int res = 0;
    for (int i = 1; i <= n; ++ i) {
        memset(st, 0, sizeof st);
        if (find(i)) res ++ ;
    }
    
    cout << n - res << endl;
    
    return 0;
}